<?php
function bend_role(&$retparams){
	global $_db;
	
	if("addview"==$_POST['op']){
		echo rendertpl("applet/roleaddmod.applet", array("title"=>"添加案例"));
		return BEND_RENDERED;
	}
	elseif("add"==$_POST['op']){
		$id = $_db->insert("role", array("name"=>@$_POST['name'],"desc"=>@$_POST['desc']));
		if($id>0){
			$retparams['errorcode'] = 0;
		}
		else{
			$retparams['errorcode'] = -1;
		}
		return BEND_ECHORET;
	}
	elseif("del"==$_POST['op']){
		$count = $_db->delete("role", "id=$_POST[id]");
	}
	elseif("modview"==$_POST['op']){
		echo rendertpl("applet/roleaddmod.applet", array("title"=>"修改案例"));
		return BEND_RENDERED;
	}
	elseif("mod"==$_POST['op']){
		$count = $_db->update("role", array("name"=>@$_POST['name'],"desc"=>@$_POST['desc']),"id=$_POST[id]");
		if($count>0){
			$retparams['errorcode'] = 0;
		}
		else{
			$retparams['errorcode'] = -1;
		}
		return BEND_ECHORET;
	}
	elseif("search"==$_POST['op']){
		return BEND_HOMEPAGE;
	}
	elseif("roleusermng"==$_POST['op']){
		echo rendertpl("applet/roleusermng.applet", array("title"=>"修改案例"));
		return BEND_RENDERED;
	}
	elseif("roleusermngsubmit"==$_POST['op']){
		error_log(print_r($_POST,1));
		$_db->delete("userrole", "roleid='$_POST[id]'");
		foreach(@$_POST['user'] as $user){
			$_db->insert("userrole", array("roleid"=>$_POST['id'], "userid"=>$user));
		}
		return BEND_REDIRECT;
	}
	return BEND_REDIRECT;
}
?>